package com.example.controller;

import com.example.entity.Tag;
import com.example.service.TagService;
import com.example.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/content/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/listAllTag")
    public ResponseResult listAllTag(){
        return ResponseResult.okResult(tagService.listAllTag());
    }

    @GetMapping("/list")
    public ResponseResult getList(@PathParam("pageNum") int pageNum, @PathParam("pageSize") int pageSize, @PathParam("name") String name){
        return tagService.getList(pageNum,pageSize,name);
    }

    @PostMapping()
    public ResponseResult saveTag(@RequestBody Tag tag){
        return tagService.saveTag(tag);
    }

    @GetMapping("/{id}")
    public ResponseResult getTag(@PathVariable Long id){
        return ResponseResult.okResult(tagService.getById(id));
    }

    @PutMapping()
    public ResponseResult updateTag(@RequestBody Tag tag){
        tag.setUpdateTime(new Date());
        return ResponseResult.okResult(tagService.updateById(tag));
    }

    @DeleteMapping("/{ids}")
    public ResponseResult deleteTags(@PathVariable List<Long> ids){
        return ResponseResult.okResult(tagService.removeByIds(ids));
    }
}
